package com.laopan.elasticsearch.bean;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

import java.io.IOException;

/**
 * <p>
 *
 * </p>
 *
 * @author laopan
 * @className FieldArray
 * @date 2021/4/16 16:23
 */

public class UpdateFieldArray {
    private String id;
    private String filedName;
    private String[] filedData;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFiledName() {
        return filedName;
    }

    public void setFiledName(String filedName) {
        this.filedName = filedName;
    }

    public String[] getFiledData() {
        return filedData;
    }

    public void setFiledData(String[] filedData) {
        this.filedData = filedData;
    }

    public XContentBuilder getUpdateContent() {
        try {
            return XContentFactory.jsonBuilder()
                    .startObject()
                    .array(getFiledName(), getFiledData())
                    .endObject();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
